//+------------------------------------------------------------------+ //| Example of Center Object on Chart.mq4 | //| Copyright © 2009, Sergey Lykov | //| http://mtexperts.narod.ru/ | //| [EA]: Example of Center Object on Chart | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, Serega Lykov" #property link "http://mtexperts.narod.ru/" //---- external parameters ------------------------------------------+ extern int Window_Index = 0; // index of window: 0 = main chart extern string TxtMessage = "This is text at center of chart"; extern int FontSize = 10; extern string FontName = "Arial"; extern color TextColor = Snow; //---- global variables ---------------------------------------------+ static string Txt_objname = "Example object"; //-------------------------------------------------------------------+ //---- initialization of expert -------------------------------------+ //-------------------------------------------------------------------+ int init() { return(0); } //-------------------------------------------------------------------+ //---- deinitialization of expert -----------------------------------+ //-------------------------------------------------------------------+ int deinit() { ObjectDelete(Txt_objname); return(0); } //-------------------------------------------------------------------+ //---- main programm cycle ------------------------------------------+ //-------------------------------------------------------------------+ int start() { int window_index = ObjectFind(Txt_objname); if(window_index < 0) { datetime obj_time1 = Time[WindowFirstVisibleBar() - WindowBarsPerChart() / 2]; double obj_price1 = NormalizeDouble((WindowPriceMax(Window_Index) + WindowPriceMin(Window_Index)) / 2,Digits); ObjectCreate(Txt_objname,OBJ_TEXT,Window_Index,obj_time1,obj_price1); ObjectSetText(Txt_objname,TxtMessage,FontSize,FontName,TextColor); } else { obj_time1 = Time[WindowFirstVisibleBar() - WindowBarsPerChart() / 2]; obj_price1 = NormalizeDouble((WindowPriceMax(window_index) + WindowPriceMin(window_index)) / 2,Digits); if(obj_time1 != ObjectGet(Txt_objname,OBJPROP_TIME1) || obj_price1 != NormalizeDouble(ObjectGet(Txt_objname,OBJPROP_PRICE1),Digits)) ObjectMove(Txt_objname,0,obj_time1,obj_price1); } return(0); } //-------------------------------------------------------------------+